package io.renren.modules.web.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.entity.FileManagerEntity;
import io.renren.modules.sys.service.FileManagerService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-01-07 10:10:53
 */
@RestController
@RequestMapping("web/filemanager")
public class WebFileManagerController {
    @Autowired
    private FileManagerService fileManagerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        List<FileManagerEntity> list = fileManagerService.queryList(params);
        return R.ok().put("list", list);
    }


    /**
     * 列表
     */
    @RequestMapping("/listPage")
    public R listPage(@RequestParam Map<String, Object> params){
        PageUtils page = fileManagerService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{fileName}")
    public R list(@PathVariable("fileName") String fileName){
        FileManagerEntity fileManagerEntity = fileManagerService.selectOne(new EntityWrapper<FileManagerEntity>().like("attach_path",fileName));
        return R.ok().put("fileManagerEntity", fileManagerEntity);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
			FileManagerEntity fileManager = fileManagerService.selectById(id);

        return R.ok().put("fileManager", fileManager);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody FileManagerEntity fileManager){
			fileManagerService.insert(fileManager);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody FileManagerEntity fileManager){
			fileManagerService.updateById(fileManager);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
			fileManagerService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
